<template>
  <view>
    <my-message-top :text="'猫咪详情'"></my-message-top>
    
    <view class="cat-pic">
      <text class="cat-p1">示例图片（点击下方链接查看）：</text>
      
      <uni-link :href="catDetail.coverURL" text="猫咪图片"></uni-link>

    </view>
    
    <view class="cat-detail">
      <text>可信任度（0-100）</text>
      <text>{{catDetail.trust}}</text>
      <text>名字</text>
      <text>{{catDetail.name}}</text>
      <text>特点</text>
      <text>{{catDetail.feature}}</text>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        file: '',
        catDetail: {}
      };
    },
    onLoad(option){
      this.file = option.file
      console.log(this.file);
      this.getCatDetail()
    },
    methods:{
      async getCatDetail(){
        uni.showLoading({
            title: '数据加载中...',
          })
        const token = uni.getStorageSync('token')
        const res = await uni.uploadFile({
            url: 'http://www.newbabyya.com/utils/identifyCat',   
            filePath: this.file,   
            name: 'file', 
            method: 'post',
            header:{
                   'Authorization': token
                  } 
        }); 
        console.log(JSON.parse(res[1].data).data.list[0]);
        this.catDetail = JSON.parse(res[1].data).data.list[0]
       uni.hideLoading()
      }
    }
  }
</script>

<style lang="scss">
.cat-pic{
  width: 680rpx;
  height: 168rpx;
  background-color: #FFEFEF;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  margin: 35rpx 35rpx;
  .cat-p1{
    font-size: 15px;
    font-weight: bold;
    color: #666666;
    padding: 25rpx 35rpx;
  }
  uni-link{
    padding-left: 35rpx;
    padding-bottom: 25rpx;
  }
}

.cat-detail{
  width: 680rpx;
  height: 2500rpx;
  background-color: #FFF7E9;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
  margin-left: 35rpx;
  text{
    font-size: 15px;
    font-weight: bold;
    color: #666666;
    padding: 35rpx 35rpx;
  }
}
</style>
